from urllib import request
import re

def find_chapter_infos(url):
    headers = {
        'User-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Mobile Safari/537.36'
    }
    req = request.Request(url=url, headers=headers)
    response = request.urlopen(req)
    html = response.read().decode('utf-8')
    chapter_info_regex = r'<a\sclass=\"chapter-info\"\shref=\"(?P<path>[^\"]+)\"\starget=\"_self\"\stitle=\"(?P<chapter_name>[^\"]+)\">'
    chapter_infos = re.findall(chapter_info_regex, html)
    return chapter_infos


def get_img_urls_from_page(page_url):
    headers = {
        'User-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Mobile Safari/537.36'
    }
    req = request.Request(url=page_url, headers=headers)
    response = request.urlopen(req)
    html = response.read().decode('utf-8')
    image_regex = r'image-loading=\"(?P<img_url>[^\"]+)\"\salt=\"(?P<img_name>[^\"]+)\.jpg\"'
    image_urls = re.findall(image_regex, html)
    return image_urls
